﻿using System.Collections.Generic;
using HDSmartCommunity.Models;

namespace HDSmartCommunity.DAL
{
    public class AudioDAL
    {
        public bool InsertAudio(AudioInfo audioInfo)
        {
            try
            {
                string strSql = string.Format("INSERT INTO audio_info(id,filename,path,state)VALUES({0},'{1}','{2}','未上传')", audioInfo.id, audioInfo.filename, audioInfo.path);

                CommFN<AudioInfo> fn = new CommFN<AudioInfo>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }

        public bool UpdateAudio(AudioInfo audioInfo)
        {
            try
            {
                string strSql = string.Format("UPDATE audio_info SET filename='{1}' ,path='{2}',state='未上传' WHERE id={0}", audioInfo.id, audioInfo.filename, audioInfo.path);

                CommFN<AudioInfo> fn = new CommFN<AudioInfo>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }

        public bool UpdateAudioState(int id)
        {
            try
            {
                string strSql = string.Format("UPDATE audio_info SET state='上传成功' WHERE id={0}", id);

                CommFN<AudioInfo> fn = new CommFN<AudioInfo>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteAudio(AudioInfo audioInfo)
        {
            try
            {
                string strSql = "DELETE FROM audio_info WHERE id="+audioInfo.id;

                CommFN<AudioInfo> fn = new CommFN<AudioInfo>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }

        public AudioInfo CheckAudio(int audioid)
        {
            string strSql = string.Format("SELECT * from audio_info where id={0} limit 0,1", audioid);
            CommFN<AudioInfo> fn = new CommFN<AudioInfo>();
            return fn.GetData(strSql);
        }

        public List<AudioInfo> QueryAudio()
        {
            string strSql = "SELECT * FROM audio_info";

            CommFN<AudioInfo> fn = new CommFN<AudioInfo>();
            return fn.GetDataList(strSql);
        }
    }
}
